package com.t3go.t3_map.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.shareware.common.utils.ScreenExtKt;
import com.t3go.t3_map.R;
import com.t3go.t3_map.entity.GuideEntity;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class ImageGuideView extends FrameLayout {


    private ImageView imageView;
    private Scene mScene;

    private GuideEntity mData;

    public enum Scene {
        //首页地图
        HOME(0),

        // 起点地图选择
        START_SELECT(1),

        //呼叫页
        CALLING(2),

        //等待接驾
        PICKUP(3);

        public int getType() {
            return type;
        }

        final int type;

        Scene(int type) {
            this.type = type;
        }
    }


    public ImageGuideView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public ImageGuideView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ImageGuideView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(@NonNull Context context) {
        LayoutInflater.from(context).inflate(R.layout.walit_image_text_guide, this);
        setElevation(0);
        imageView = findViewById(R.id.image);
    }

    public void bindData(GuideEntity data, Scene scene) {
        mData = data;
        mScene = scene;

        Context context = getContext();
        if (context == null) {
            return;
        }

        RoundedCornersTransformation transformation = new RoundedCornersTransformation(
                ScreenExtKt.dp2px(context, 4f),
                0, RoundedCornersTransformation.CornerType.ALL
        );
        Glide.with(context)
                .load(data.getGuideMainUrl())
                .transform(transformation)
                .override(ScreenExtKt.dp2px(36f), ScreenExtKt.dp2px(30f))
                .error(R.drawable.icon_guide_default)
                .into(imageView);
    }
}
